package com.tcgroup.phone.base_core.framework.mvvm.netregister;

import android.app.Application;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * 作者: wangfei
 * 创建时期: 2020/3/16.
 * 包名: com.tcgroup.phone.base_core.framework.mvvm.netregister
 * 类名: HibeautyNew-Android
 */
public class BaseNetRegister implements INetRegister {

    Application mApplication;
    //1、可以快速解除所有添加的Disposable类.
    //2、每当我们得到一个Disposable时就调用CompositeDisposable.add()将它添加到容器中,
    // 在退出的时候, 调用CompositeDisposable.clear() 即可快速解除.
    CompositeDisposable mCompositeDisposable;

    public BaseNetRegister(Application mApplication) {
        this.mApplication = mApplication;
    }

    public BaseNetRegister() {
    }

    public void addSubscribe(Disposable disposable) {
        if (mCompositeDisposable == null) {
            mCompositeDisposable = new CompositeDisposable();
        }
        mCompositeDisposable.add(disposable);
    }

    @Override
    public void onCleared() {
        if (null != mCompositeDisposable){
            mCompositeDisposable.clear();
        }
    }
}
